/*
 * Copyright (C) 2015 andrea
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package meteocal.boundary;

import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import meteocal.entity.Users;
import meteocal.entityManager.UserManager;

/**
 *
 * @author andrea
 */
@ManagedBean
@ViewScoped
public class FavoriteGridView implements Serializable {
    
    @Inject
    UserManager um;
    
    private List<Users> favorites;
    
    private Users selectedFavorite;
    
    @PostConstruct
    public void init(){
        setFavorites(um.getLoggedUser().getFavorites());
        setSelectedFavorite(null);
    }

    /**
     * @return the favorites
     */
    public List<Users> getFavorites() {
        return favorites;
    }

    /**
     * @param favorites the favorites to set
     */
    public void setFavorites(List<Users> favorites) {
        this.favorites = favorites;
    }

    /**
     * @return the selectedFavorite
     */
    public Users getSelectedFavorite() {
        return selectedFavorite;
    }

    /**
     * @param selectedFavorite the selectedFavorite to set
     */
    public void setSelectedFavorite(Users selectedFavorite) {
        this.selectedFavorite = selectedFavorite;
    }
    
    public String visitFavorite(){
        return "/user/UserPage?faces-redirect=true&amp;email="+selectedFavorite.getEmail();
    }
    
}
